<extend name="Public:main" />
<block name="title">登录</block>
<block name="custom_css">
    <link rel="stylesheet" href="__PUBLIC__/js/nice-validator-0.10.11/dist/jquery.validator.css">
</block>
<block name="body">
<body ng-app="myApp" ng-controller="Ctrl" ng-cloak>
    <div class="nav_top flex">
        <a  href="{:U('Index/index')}">
            <i></i>
        </a>
        <div class="flex1">
            登陆
        </div>
        <a href="javascript:void(0)">
            <i></i>
        </a>
    </div>
    <div style="height: 0.44rem;"></div>
    <div class="login">
        <form action="" method="post">
            <div>
                <label>手机号/UID</label>
                <input type="text" name="account" placeholder="手机号/UID" onInput ="returnNum(this)" maxlength="11">
            </div>
            <div>
                <label>登陆密码</label>
                <input type="password" name="password" placeholder="登陆密码">
            </div>
        </form>
    </div>
    <input class="login_btn" type="button" ng-click="login()" value="登陆">
    <div class="go_rf clearfix"> 
        <a href="{:U('Register/register')}">
            立即注册
        </a>
        <a href="{:U('Register/forgetPasswd')}">
            忘记密码？
        </a>
    </div>
</body>
<block name="custom_js">
    <script src="__PUBLIC__/js/nice-validator-0.10.11/dist/jquery.validator.js"></script>
    <script>
        function returnNum(_this) {
            _this.value = _this.value.replace(/[^0-9]/g, '');
        }
    </script>
    <script>
        var app = getApp('myApp', []);
        app.controller('Ctrl', function ($scope, $http) {
            $scope.login = function () {
                var valida = $('form').trigger("validate").data("validator").isFormValid();//有表单验证的地方用 这个方法
                if (valida) {
                    $http({
                        method: 'POST',
                        data: {
                            "account" : $("input[name='account']").val(),
                            "password" : $("input[name='password']").val(),
                        },
                        headers: {'Content-Type': 'application/x-www-form-urlencoded'},
                        transformRequest: function (obj) {
                            var str = [];
                            for (var p in obj) {
                                str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
                            }
                            return str.join("&");
                        },
                        url: "/index.php/Home/Login/login"
                    }).then(function successCallback(response) {
                        if (response.data.code == -1) {
                            layer.msg(response.data.msg, {time: 1000})
                        } else if (response.data.code == 0) {
                            layer.msg(response.data.data.msg, {time: 1000})
                            setTimeout(function () {
                                window.location.href = '/index.php/Home/Index/index'
                            }, 1000)
                        }
                    }, function errorCallback(response) {
                        errorHandle(response);
                    });
                }
            }
        });
    </script>
</block>
</block>